<template>
<div class="app-container calendar-list-container">
  <!-- <div class="filter-container">
     <el-button-group>
      <el-button type="primary" v-if="menuManager_btn_del" icon="delete" @click="handleBack">返回</el-button>
    </el-button-group>
  </div> -->

<el-row>
  <el-col :span="24">
    <!-- 基本信息 START-->
     <el-card class="box-card">
       <div slot="header" class="clearfix">
          <span>基本信息</span>
        </div>
        <el-form :label-position="labelPosition" :rules="formRules" label-width="100px" :model="baseForm" ref="baseForm">
          <el-row>
            <el-col :span="12">
                <el-form-item label="姓名" prop="name">
                    <el-input v-model="baseForm.name" placeholder="请输入姓名"></el-input>
                </el-form-item>
            </el-col>
            <el-col :span="12">
                  <el-form-item label="性别" prop="sex">
                    <el-select class="filter-item" v-model="baseForm.sex"   placeholder="请选择性别">
                      <el-option v-for="item in  sexOptions" :key="item.value" :label="item.label" :value="item.value"> </el-option>
                    </el-select>
                  </el-form-item>
            </el-col>
          </el-row>

           <el-row>
              <el-col :span="24">
                <el-form-item label="当前所在地" prop="provinceId">
                  <el-col :span="11">
                      <el-select class="filter-item" v-model="baseForm.provinceName" placeholder="请选择省份" style="width: 100%;" value-key="id" @change="provinceChange">
                        <el-option v-for="item in  provinceOptions" :key="item.id" :label="item.name" :value="item"> </el-option>
                      </el-select>
                  </el-col>
                  <el-col class="line text-center" :span="2">-</el-col>
                  <el-col :span="11">
                      <el-select class="filter-item" style="width: 100%;" v-model="baseForm.cityName" placeholder="请选择所在地市区" value-key="id" @change="cityChange">
                        <el-option v-for="item in  cityOptions" :key="item.id" :label="item.name" :value="item"> </el-option>
                      </el-select>
                  </el-col>
                </el-form-item>
              </el-col>
          </el-row>
          <el-row>
            <!-- <el-col :span="12">
                <el-form-item label="生日" prop="birthday">
                    <el-date-picker type="date" placeholder="选择日期" v-model="baseForm.birthday" style="width: 100%;" value-format=" yyyy-MM-dd" format="yyyy-MM-dd"></el-date-picker>
                </el-form-item>
            </el-col> -->
            <el-col :span="12">
                <el-form-item label="联系电话" prop="phone">
                    <el-input v-model="baseForm.phone" placeholder="请输入联系电话"></el-input>
                </el-form-item>
            </el-col>
            <el-col :span="12">
                <el-form-item label="民族" prop="nation">
                    <el-select class="filter-item" style="width: 100%;" v-model="baseForm.nation" placeholder="请选择民族">
                        <el-option v-for="item in  nationOptions" :key="item" :label="item" :value="item"> </el-option>
                    </el-select>
                </el-form-item>
            </el-col>
          </el-row>
          <el-row>
            <el-col :span="12">
                <el-form-item label="微信" prop="wx">
                    <el-input v-model="baseForm.wx" placeholder="请输入微信"></el-input>
                </el-form-item>
            </el-col>
            <el-col :span="12">
                <el-form-item label="QQ" prop="qq">
                    <el-input v-model="baseForm.qq"  placeholder="请输入QQ"></el-input>
                </el-form-item>
            </el-col>
          </el-row>
          <el-row>
            <el-col :span="24">
                <el-form-item label="身份证号" prop="idCard">
                    <el-input v-model="baseForm.idCard" :disabled="idCardDisabled" placeholder="请输入身份证号"></el-input>
                </el-form-item>
            </el-col>
          </el-row>
          <el-row>
            <el-col :span="24">
                <el-form-item label="联系地址" prop="addr">
                    <el-input type="textarea" :autosize="{ minRows: 3, maxRows: 5}" placeholder="请输入联系地址" v-model="baseForm.addr"> </el-input>
                </el-form-item>
            </el-col>
          </el-row>

          <el-row class="text-right">
            <el-col :span="24">
              <el-form-item>
                <el-button v-if="baseForm.id" type="primary" @click="create(baseForm,'baseForm')">更新</el-button>
                <el-button v-else type="primary" @click="create(baseForm,'baseForm')">保存</el-button>
                <el-button v-if="!isPTYH" @click="onCancel">返回</el-button>
              </el-form-item>
            </el-col>
          </el-row>

        </el-form>
     </el-card>
     <!-- 基本信息 END-->
    
    <!-- 教育信息 START-->
    <el-card class="box-card" v-for="(edu,index) in eduFormList" :key="edu.id">
        <div slot="header" class="clearfix">
          <span>教育信息-{{index+1}}</span>
          <el-button v-if="index == 0" type="small" icon="el-icon-circle-plus-outline" style="float: right;" @click="addResumeEdu">新增</el-button>
          <el-button v-if="index != 0" type="small" icon="el-icon-remove-outline" style="float: right;" @click="removeResumeEdu(edu.id, index)">删除</el-button>
        </div>
        <el-form :label-position="labelPosition" label-width="100px" :rules="formRules" :model="edu" ref="eduForm">
          <el-row>
            <el-col :span="24">
                <el-form-item label="学历/学位" prop="degree">
                    <el-select class="filter-item" v-model="edu.degree" placeholder="请选择学历/学位"  @change="eduDegreeChange(edu, $event, index)">
                      <el-option v-for="item in  degreeOptions" :key="item.value" :label="item.text" :value="item.value" :disabled="(item.value != 1 && eduFormList.length <= 1) || (item.value == 1 && eduFormList.length > 1)"> </el-option>
                    </el-select>
                </el-form-item>
            </el-col>
          </el-row>

          <div v-if="edu.degree == 1">
            <el-row>
              <el-col :span="12">
                  <el-tooltip class="item" effect="dark" content="届为毕业的年份" placement="right">
                    <el-form-item label="届别" label-suffix="el-icon-search" prop="sessions" class="fom-item-tip tip-jie">
                      <el-select class="filter-item" style="width: 100%;" v-model="edu.sessions" placeholder="请选择届别"  @change="eduJieChange(edu, $event, index)">
                        <el-option v-for="item in  jieOptions" :key="item" :label="'第' + item +'届'" :value="item"> </el-option>
                      </el-select>
                    </el-form-item>
                  </el-tooltip>
              </el-col>
              <el-col :span="12">
                  <el-form-item label="学校" prop="schoolName">
                      <!-- <el-select class="filter-item" v-model="edu.schoolName" placeholder="请选择学校" style="width: 100%;"  value-key="schoolId" @change="eduSchoolChange(edu, $event, index)">
                        <el-option v-for="item in  schoolObjOptions[index]" :key="item.schoolId" :label="item.schoolName" :value="item"> </el-option>
                      </el-select> -->

                      <el-select class="filter-item" style="width: 100%;" v-model="edu.schoolName" placeholder="请选择学校" value-key="schoolId" @change="eduSchoolChange(edu, $event,index)">
                        <el-option v-for="item in  schoolObjOptions[index]" :key="item.schoolId" :label="item.schoolName" :value="item"> </el-option>
                      </el-select>
                  </el-form-item>
              </el-col>

                  <!-- <el-col :span="12">
                      <el-select class="filter-item" style="width: 100%;" v-model="work.cityName" placeholder="请选择所在地市区" value-key="id" @change="workCityChange(work, $event,index)">
                        <el-option v-for="item in  workCityOptions[index]" :key="item.id" :label="item.name" :value="item"> </el-option>
                      </el-select>
                  </el-col> -->

            </el-row>
            <el-row>
              <el-col :span="12">
                  <el-form-item label="班级" prop="className">
                      <!-- <el-input v-model="edu.className"  placeholder="请输入班级"></el-input> -->
                    <el-select class="filter-item" v-model="edu.className" placeholder="请选择班级" style="width: 100%;" value-key="classId" @change="eduClassChange(edu, $event,index)">
                      <el-option  v-for="item in  clsssObjOptions[index]" :key="item.classId" :label="item.className" :value="item"> </el-option>
                    </el-select>
                  </el-form-item>
              </el-col>
              <el-col :span="12">
                  <el-form-item label="学籍号" prop="studentNo">
                      <el-input v-model="edu.studentNo"  placeholder="请输入学籍号"></el-input>
                  </el-form-item>
              </el-col>
            </el-row>
          </div>

          <div v-if="edu.degree != 1">

            <el-row>
              <el-col :span="12">
                  <el-form-item label="毕业院校" prop="schoolName">
                      <el-input v-model="edu.schoolName"  placeholder="请输入学校"></el-input>
                  </el-form-item>
              </el-col>
              <el-col :span="12">
                  <el-form-item label="毕业时间" prop="endTime">
                    <el-date-picker type="date" placeholder="选择毕业时间" @focus="eduEndTimeFocus(index)" :picker-options="pickerOptions3" v-model="edu.endTime" value-format="yyyy-MM-dd" format="yyyy-MM-dd" style="width: 100%;"></el-date-picker>
                  </el-form-item>
              </el-col>
            </el-row>

            <el-row>
              <el-col :span="24">
                  <el-form-item label="专业" prop="profession">
                      <el-input v-model="edu.profession"  placeholder="请输入专业"></el-input>
                  </el-form-item>
              </el-col>
            </el-row>
            <el-row>
              <el-col :span="24">
                  <el-form-item label="专业描述" prop="professionDiscribe">
                      <el-input type="textarea" :autosize="{ minRows: 3, maxRows: 5}" placeholder="请输入专业描述" v-model="edu.professionDiscribe"> </el-input>
                  </el-form-item>
              </el-col>
            </el-row>
          </div>

          <el-row class="text-right">
            <el-col :span="24">
              <el-form-item>
                <el-button v-if="edu.id" type="primary" @click="create(edu,'eduForm', index)">更新</el-button>
                <el-button v-else type="primary" @click="create(edu, 'eduForm', index)">保存</el-button>
                <el-button v-if="!isPTYH" @click="onCancel">返回</el-button>
              </el-form-item>
            </el-col>
          </el-row>
        </el-form>
     </el-card>
     <!-- 教育信息 END-->

    
    <!-- 工作信息 START-->
    <el-card class="box-card" v-for="(work,index) in workFormList" :key="work.id">
       <div slot="header" class="clearfix">
          <span>工作信息-{{index+1}}</span>
          <el-button v-if="index == 0" type="small" icon="el-icon-circle-plus-outline" style="float: right;" @click="addResumeWork">新增</el-button>
          <el-button v-if="index != 0" type="small" icon="el-icon-remove-outline" style="float: right;" @click="removeResumeWork(work.id,index)">删除</el-button>
        </div>
        <el-form :label-position="labelPosition" label-width="100px" :rules="workFormRules" :model="work" ref="workForm">
          <el-row>
            <el-col :span="24">
                <el-col :span="12">
                  <el-form-item label="开始时间" prop="startTime">
                      <el-date-picker type="date" :picker-options="pickerOptions2" placeholder="选择工作开始日期" @focus="workSartTimeFocusFn(work.endTime)" v-model="work.startTime" value-format="yyyy-MM-dd" format="yyyy-MM-dd" style="width: 100%;"></el-date-picker>
                  </el-form-item>
                </el-col>
                <el-col :span="12">
                  <el-form-item label="结束时间" prop="endTime">
                      <el-date-picker type="date" :picker-options="pickerOptions1" @focus="workEndTimeFocusFn(work.startTime)" placeholder="选择工作结束日期" v-model="work.endTime" value-format="yyyy-MM-dd" format="yyyy-MM-dd" style="width: 100%;"></el-date-picker>
                  </el-form-item>
                </el-col>
            </el-col>
          </el-row>

           <el-row>
              <el-col :span="24">
                  <el-col :span="12">
                    <el-form-item label="工作所在地" prop="provinceId">
                          <el-select class="filter-item" v-model="work.provinceName" placeholder="请选择省份" style="width: 100%;" value-key="id" @change="workProvinceChange(work,$event,index)">
                            <el-option v-for="item in  provinceOptions" :key="item.name" :label="item.name" :value="item"> </el-option>
                          </el-select>
                    </el-form-item>
                  </el-col>

                  <el-col :span="12">
                    <el-form-item label="" prop="cityName">
                          <el-select class="filter-item" style="width: 100%;" v-model="work.cityName" placeholder="请选择所在地市区" value-key="id" @change="workCityChange(work, $event,index)">
                            <el-option v-for="item in  workCityOptions[index]" :key="item.id" :label="item.name" :value="item"> </el-option>
                          </el-select>
                    </el-form-item>
                  </el-col>
              </el-col>
          </el-row>

          <el-row>
            <el-col :span="12">
                <el-form-item label="工作单位" prop="company">
                    <el-input v-model="work.company"  placeholder="请输入工作单位名称"></el-input>
                </el-form-item>
            </el-col>
            <el-col :span="12">
                <el-form-item label="所属行业" prop="industry">
                    <el-input v-model="work.industry"  placeholder="请输入所属行业"></el-input>
                </el-form-item>
            </el-col>
          </el-row>

          <el-row>
            <el-col :span="12">
                <el-form-item label="单位性质" prop="companyNature">
                     <el-select class="filter-item" style="width: 100%;" v-model="work.companyNature" placeholder="请选择单位性质">
                      <el-option v-for="item in  companyNatureOptions" :key="item.value" :label="item.text" :value="item.text"> </el-option>
                    </el-select>                   
                </el-form-item>
            </el-col>
            <el-col :span="12">
                <el-form-item label="所在部门" prop="department">
                    <el-input v-model="work.department" placeholder="请输入所在部门， 例如：销售部"></el-input>
                </el-form-item>
            </el-col>
          </el-row>

          <el-row>
            <el-col :span="12">
                <el-form-item label="工作职位" prop="duty">
                    <el-input v-model="work.duty"  placeholder="请输入工作职位，例如：会计"></el-input>
                </el-form-item>
            </el-col>
            <el-col :span="12">
                  <el-form-item label="专业技术职称" prop="technicalTitle">
                    <el-input v-model="work.technicalTitle"  placeholder="请输入专业技术职称，例如：会计师"></el-input>
                  </el-form-item>
            </el-col>
          </el-row>

          <el-row>
            <el-col :span="24">
                <el-form-item label="工作描述" prop="workDiscribe">
                    <el-input type="textarea" :autosize="{ minRows: 3, maxRows: 5}" placeholder="请输入专业描述" v-model="work.workDiscribe"> </el-input>
                </el-form-item>
            </el-col>
          </el-row>

          <el-row class="text-right">
            <el-col :span="24">
              <el-form-item>
                <el-button v-if="work.id" type="primary" @click="create(work,'workForm', index)">更新</el-button>
                <el-button v-else type="primary" @click="create(work, 'workForm', index)">保存</el-button>
                <el-button v-if="!isPTYH" @click="onCancel">返回</el-button>
              </el-form-item>
            </el-col>
          </el-row>
        </el-form>
     </el-card>
     <!-- 工作信息 END-->

         <!-- 自我评价 START-->
    <el-card class="box-card">
       <div slot="header" class="clearfix">
          <span>评价</span>
        </div>
        <el-form :label-position="labelPosition" label-width="100px" :rules="formRules" :model="myCommentForm" ref="myCommentForm">
          <el-row>
            <el-col :span="24">
                <el-form-item label="评价" prop="comment">
                    <el-input type="textarea" :autosize="{ minRows: 5, maxRows: 8}" placeholder="请输入评价" v-model="myCommentForm.comment"> </el-input>
                </el-form-item>
            </el-col>
          </el-row>

          <el-row class="text-right">
            <el-col :span="24">
              <el-form-item>
                <el-button v-if="myCommentForm.id" type="primary" @click="create(myCommentForm,'myCommentForm')">更新</el-button>
                <el-button v-else type="primary" @click="create(myCommentForm, 'myCommentForm')">保存</el-button>
                <el-button v-if="!isPTYH" @click="onCancel">返回</el-button>
              </el-form-item>
            </el-col>
          </el-row>
        </el-form>
     </el-card>
     <!-- 自我评价 END-->
  </el-col>
</el-row>

  <!-- 输入身份证弹框 -->
  <el-dialog :visible.sync="dialogFormVisible" :close-on-press-escape="false" :close-on-click-modal="false" :show-close="false">
    <el-form :model="idCardRelateForm" :rules="formRules" ref="idCardRelateForm" label-width="100px">
      <el-form-item label="身份证号码" prop="idCard">
        <el-input v-model="idCardRelateForm.idCard" placeholder="请输入身份证号码" style="width: 80%;"></el-input>
      </el-form-item>
    </el-form>
    <div slot="footer" class="dialog-footer">
      <el-button type="primary" @click="createIdCardRelate('form')">确 定</el-button>
    </div>
  </el-dialog>
  </div>
</template>

<script>
import Vue from "vue"
import {
  getObj, addObj, delObj, putObj,delEduObj,delWorkObj,
  getResumeBaseObj,getResumeEduObj,getResumeWorkObj,getResumeCommentObj,
  getAreaListObj,getSchoolListObj,getClassListObj,
  getIdCardObj, addIdCardRelateObj
} from 'api/admin/student/index';
import {
  fetchClassTreeObj
} from 'api/admin/talent/index';
import {
   fetchJieOptionsObj
} from 'api/admin/person/index';
import {
  staticData
} from 'mock/staticData';
import { mapGetters } from 'vuex';
export default {
  name: 'menu',
  data() {
    return {
      currrentRole: null,
      isPTYH: false,
      idCardRelateForm: {
        userId: null,
        idCard: null
      },
      filterText: '',
      list: null,
      total: null,
      formEdit: false,
      isManager: false,
      dialogFormVisible: false,
      idCardDisabled: false,
      formAdd: true,
      formStatus: 'create',
      showElement: false,
      typeOptions: ['menu', 'dirt'],
      sexOptions: [{
          value: true,
          label: '男'
        }, {
          value: false,
          label: '女'
        }],
      nationOptions: staticData.nationsData,
      listQuery: {
        name: null
      },
      defaultProps: {
        children: 'children',
        label: 'title'
      },
      labelPosition: 'right',
      //班级
      classListOptions: staticData.classListOptionsData,
      //表单规则
      formRules: {
        name: [
          {
            required: true,
            message: '请输入姓名',
            trigger: 'blur'
          },
          {
            min: 1,
            max: 20,
            message: '长度在 1 到 20 个字符',
            trigger: 'blur'
          }
        ],
        sex: [
          {
            required: true,
            message: '请选择性别',
            trigger: 'change'
          }
        ],
        provinceId: [
          {
            required: true,
            message: '请选择当前所在地省份',
            trigger: 'change'
          }
        ],
        cityId: [
          {
            required: true,
            message: '请选择当前所在地市区',
            trigger: 'change'
          }
        ],
        phone:[
          {
            pattern: /^((\d{3,4}-\d{7,8})|(\d{11}))$/,
            message: '电话格式不正确',
            trigger: 'blur'
          }
        ],
        wx:[
          {
            min: 1,
            max: 50,
            message: '微信号最大长度只支持50个字符',
            trigger: 'blur'
          }
        ],
        qq:[
          {
            min: 1,
            max: 20,
            message: 'QQ号最大长度只支持20个字符',
            trigger: 'blur'
          }
        ],
        addr:[
          {
            min: 1,
            max: 200,
            message: '联系地址最大只支持200个字符',
            trigger: 'blur'
          }
        ],
        idCard: [
          {
            required: true,
            pattern: /(^\d{15}$)|(^\d{18}$)|(^\d{17}(\d|X|x)$)/,
            message: '身份证号必须为15位或18位',
            trigger: 'blur'
          }
        ],
        degree: [
          {
            required: true,
            message: '请选择学历/学位',
            trigger: 'change'
          }
        ],
        sessions: [
          {
            required: true,
            message: '请选择届别',
            trigger: 'change'
          }
        ],
        schoolName: [
          {
            required: true,
            message: '请选择学校',
            trigger: 'change'
          }
        ],
        className: [
          {
            required: true,
            message: '请选择班级',
            trigger: 'change'
          }
        ],
        comment:[
          {
            min: 1,
            max: 1000,
            message: '评价最大长度只支持1000个字符',
            trigger: 'blur'
          }
        ]
      },
      //工作信息-表单规则
      workFormRules: {
        startTime: [
          {
            required: true,
            message: '请选择工作开始时间',
            trigger: 'change'
          }
        ],
        endTime: [
          {
            required: true,
            message: '请选择工作结束时间',
            trigger: 'change'
          }
        ],
        provinceId:[
          {
            required: true,
            message: '请选择工作所在地省份',
            trigger: 'change'
          }
        ],
        cityName:[
          {
            required: true,
            message: '请选择工作所在地市区',
            trigger: 'change'
          }
        ],
        workDiscribe:[
          {
            min: 1,
            max: 500,
            message: '工作描述最大长度只支持500个字符',
            trigger: 'blur'
          }
        ]
      },
      baseForm: {
        id: null,
        name: null,
        sex: null,
        age: 0,
        provinceId: null,
        provinceName: null,
        cityId: null,
        cityName: null,
        birthday: null,
        nation: null,
        phone: null,
        qq: null,
        wx: null,
        idCard: null,
        addr: null
      },
      eduFormList: [
          {
          id: null,
          degree: 1,
          sessions: null,
          schoolId: null,
          schoolName: null,
          classId: null,     
          className: null,     
          sessions:null,
          startTime: null,
          endTime: null,
          studentNo: null,
          idCard: null
        }
      ],
      schoolObjOptions:[],
      clsssObjOptions:[],
      eduForm: {
        id: null,
        degree: 1,
        sessions: null,
        schoolId: null,
        schoolId: null,
        classId: null,
        className: null,
        startTime: null,
        endTime: null,
        studentNo: null,
        idCard: null
      },
      workFormList:[
          {
          id: null,
          startTime: null,
          endTime: null,
          provinceName: null,
          provinceId: null,
          cityId:null,
          cityName:null,
          company: null,
          industry: null,
	        companyNature: null,
	        department: null,
          duty: null,
          technicalTitle: null,
          workDiscribe: null,
          enabled: null,
        }
      ],
      //结束时间option
      pickerOptions1:{},
      //开始时间option
      pickerOptions2:{},
      //教育信息-毕业时间option
      pickerOptions3:{},
      workProvinceOptions:[],
      workCityOptions:[],
      workForm: {
        id: null,
        startTime: null,
        endTime: null,
        provinceName: null,
        provinceId: null,
        cityId:null,
        cityName:null,
        company: null,
        industry: null,
        companyNature: null,
        department: null,
        duty: null,
        technicalTitle: null,
        workDiscribe: null,
        enabled: null,
      },
      myCommentForm: {
        id: null,
        comment: null
      },
      currentId: -1,

      degreeOptions: staticData.degreeOptionsData,
      compnaySizeOptions: staticData.compnaySizeOptionsData,
      companyNatureOptions: staticData.companyNatureList,
      provinceOptions: [],
      schoolOptionObj: [],
      cityOptions: [],
      jieOptions:[]
    }
  },
  watch: {
    filterText(val) {
      this.$refs.menuTree.filter(val);
    }
  },
  created() {
    this.isManagerRole();
    // var idCard = this.$route.query.idCard;
    var idCard = window.localStorage.getItem('currentIdCard');
    //如果是管理员添加简历，则不需要获取idCard
    var role = this.$store.getters.roles[0];
    this.currrentRole = role;
    //只有普通用户才去获取其身份证关联关系
    if(role.code == 'PTYH'){
      this.isPTYH = true;
      this.getUserIdCard();
    }else{
      if(idCard){
        this.getResumeAll(idCard);
      }
    }
    //初始化届下拉数据
    this.getJieOptions();
    //初始化省市下拉数据
    this.getAreaList('');
    
  },
  computed: {
    ...mapGetters([
      'elements'
    ])
  },
  methods: {
    isManagerRole(){
      var currentName = this.$store.getters.name;
      //暂时先按管理员处理TODO
      if(currentName == 'Mr.AG'){
        this.isManager = true;
      }
    },
    getUserIdCard() {
      getIdCardObj().then(res => {
        if(res.data && res.data.idCard){
          this.idCardRelateForm = res.data;
          //将身份证号赋值给baseForm上
          this.baseForm.idCard = res.data.idCard;
          this.getResumeAll( res.data.idCard);
        }else{
          this.idCardRelateForm.userId = res.data.userId;
          //如果用户没有绑定身份证号，则弹框
          this.dialogFormVisible = true;
        }
      });
    },
    createIdCardRelate(){
      var that = this;
      this.$refs.idCardRelateForm.validate(valid => {
        if (valid) {
          let idCardBind = that.idCardRelateForm.idCard;
          addIdCardRelateObj(that.idCardRelateForm).then((res) => {
              that.dialogFormVisible = false;
              that.$notify({
                title: '成功',
                message: '绑定身份证号成功',
                type: 'success',
                duration: 2000
              });
              //设置baseForm的身份证号
              this.baseForm.idCard = idCardBind;
              //加载简历各个模块的数据
              that.getResumeAll(idCardBind);
            })
        } else {
          return false;
        }
      });
    },
    getResumeAll(idCard){
      this.getResumeBase(idCard);
      this.getResumeEdu(idCard);
      this.getResumeWork(idCard);
      this.getResumeComment(idCard);
    },
    getAreaList(pid) {
      getAreaListObj(pid).then(res => {
        this.provinceOptions = res.data;
      });
    },
    provinceChange(data){
      
      this.baseForm.provinceId = data.id;
      this.baseForm.provinceName = data.name;
      this.baseForm.cityId = '';
      this.baseForm.cityName = '';
      getAreaListObj(data.id).then(res => {
        this.cityOptions = res.data;
      });
    },
    cityChange(data){
      this.baseForm.cityId = data.id;
      this.baseForm.cityName = data.name;
    },
    setBirthday(){
      //生日和年龄自动获取
      let idCardVal = this.baseForm.idCard;
      if(this.formRules.idCard[0].pattern.test(idCardVal)){
        let birthdayStr = idCardVal.substring(6,14),
        birthYear = birthdayStr.substring(0,4),
        birthMonth = birthdayStr.substring(4,6),
        birthDay = birthdayStr.substring(6,8);
        this.baseForm.birthday = birthYear+ '-' + birthMonth+ '-' + birthDay;
      }
    },
    setAge(){
      //生日和年龄自动获取
      let idCardVal = this.baseForm.idCard;
      if(this.formRules.idCard[0].pattern.test(idCardVal)){
        let birthYear = idCardVal.substring(6,10)
        this.baseForm.age = new Date().getFullYear() - parseInt(birthYear);
      }
    },
    filterNode(value, data) {
      if (!value) return true;
      return data.label.indexOf(value) !== -1;
    },
    getResumeBase(idCard) {
      //管理员(包含4中管理员)类型时，身份证不禁用
      if(idCard && this.currrentRole.code == 'PTYH'){
        this.idCardDisabled = true;
      }
      getResumeBaseObj(idCard).then(response => {
        if(response.data && response.data.base){
          this.baseForm = response.data.base;
        }
      });
    },
    getResumeEdu(idCard) {
      getResumeEduObj(idCard).then(response => {
        // this.eduForm = response.data.edu[0];
        if(response.data.edu && response.data.edu.length > 0){
          let list  = this.orderEduFormList(response.data.edu);
          this.eduFormList = list;
          //初始化届-学校下拉列表数据
          // this.eduFormList.forEach((edu, index) => {
          //   this.jieChange(edu,index);
          // });
        }
      });
    },
    orderEduFormList(list){
      if(list && list.length){
        for(let i=0; i<list.length; i++){
          for(let j=i+1; j<list.length; j++){
            var temp = '';
            if(list[j].degree < list[i].degree){
              temp = list[j]
              list[j] = list[i]
              list[i] = temp
            }
          }
        }
      }
      return list
    },
    getResumeWork(idCard) {
      this.getWorkProvinceOptions();
      getResumeWorkObj(idCard).then(response => {
        // this.workForm = response.data.work[0];
        if(response.data && response.data.work && response.data.work.length > 0){
          this.workFormList = response.data.work;
        }
      });
    },
    getResumeComment(idCard) {
      getResumeCommentObj(idCard).then(response => {
        if(response.data.comment){
          this.myCommentForm = response.data.comment;
        }
      });
    },
    handlerEdit() {
      if (this.form.id) {
        this.formEdit = false;
        this.formStatus = 'update';
      }
    },
    handlerAdd() {
      this.resetForm();
      this.formEdit = false;
      this.formStatus = 'create';
    },
    handleDelete() {
      this.$confirm('此操作将永久删除, 是否继续?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        delObj(this.currentId).then(() => {
          this.resetForm();
          this.onCancel();
          this.$notify({
            title: '成功',
            message: '删除成功',
            type: 'success',
            duration: 2000
          });
        });
      }).catch(() => {
          //点击取消         
      });
    },

    update() {
      putObj(this.form.id, this.form).then(() => {
        this.$notify({
          title: '成功',
          message: '更新成功',
          type: 'success',
          duration: 2000
        });
      });
    },
    //简历各模块统一保存
    create(currentForm, type, index) {
      var that = this,
      idCard;
      //保存每种表单前，必须先输入身份证号
      idCard = that.baseForm.idCard;
      if(!idCard || !that.formRules.idCard[0].pattern.test(idCard)){
        this.$message({
          message: '请先填写身份证号',
          type: 'warning'
        });
        return;
      }
      //给每种表单设置idCard
      currentForm.idCard = idCard;
      //如果是baseForm，则计算生日
      if(type == 'baseForm'){
        that.setBirthday();
        that.setAge();
      }
      const set = this.$refs;
      var flag = false;
      var vueComponent = set[type];
      if(set[type] instanceof Array){
          set[type].forEach(ele => {
              ele.validate(valid => {
              if (valid) {
                return true;
              } else {
                flag = false;
                return false;
              }
            });
          });
          vueComponent = set[type][index];
      }

      vueComponent.validate(valid => {
        if (valid) {
          addObj(currentForm, type)
            .then((res) => {
              //给当前表单的id赋值，再次点击的时候就是修改
              currentForm.id = res.data.id;
              that.$notify({
                title: '成功',
                message: '操作成功',
                type: 'success',
                duration: 2000
              });
            })
        } else {
          return false;
        }
      });
    },

    onCancel() {
      // this.formEdit = true;
      // this.formStatus = '';
      this.$router.push({ path: '/talentManager/talentList' });
    },
    resetForm() {
      this.form = {
        code: null,
        title: null,
        parentId: this.currentId,
        href: null,
        icon: null,
        orderNum: null,
        description: null,
        path: null,
        enabled: null
      };
    },
    handleBack(){
      window.history.go(-1);
      // window.close();
    },
    /**
     * 教育信息相关
     */
    //获取届列表
    getJieOptions() {
      fetchJieOptionsObj().then(res => {
        if(res && res.data){
          this.jieOptions = res.data;
        }
      });
    },

    eduDegreeChange(){
      let hasGaozhong = this.isHasGaozhongFn();
      if(!hasGaozhong){
        this.$message({
          message: '请先填写高中教育信息',
          type: 'warning'
        });
        this.degreeOptions[0].value;
      }
    },

    eduJieChange(edu, data, index){
      edu.schoolId = '';
      edu.schoolName = '';
      edu.classId = '';
      edu.className = '';
      //sessions就是届(如：2018)
      var obj = {
        sessions: edu.sessions
      };
      getSchoolListObj(obj).then(res => {
        //将不同下标的学校列表，放到obj这个对象上去
        if(res && res.data){
          this.schoolObjOptions[index] = res.data;
          //解决动态改变数据不刷新问题
          Vue.set(this.schoolObjOptions, index, res.data)
        }
      });
    },
    eduSchoolChange(edu, data, index){
      edu.schoolId = data.schoolId;
      edu.schoolName = data.schoolName;
      edu.classId = '';
      edu.className = '';

      var obj = {
        sessions: edu.sessions,
        schoolId: edu.schoolId,
      };
      getClassListObj(obj).then(res => {
        //根据届和学校获取对应班级
        if(res && res.data){
          this.clsssObjOptions[index] = res.data;
          //解决动态改变数据不刷新问题
          Vue.set(this.clsssObjOptions, index, res.data);
        }
      });
    },
    eduClassChange(edu, data, index){
      Vue.set(this.clsssObjOptions, index, data)
      edu.classId = data.classId;
      edu.className = data.className;
    },

    //添加教育程度
    addResumeEdu(){
      //教育列表中是否有高中
      let hasGaozhong = this.isHasGaozhongFn();
      //只要有高中，则默认从大专开始
      if(hasGaozhong){
        this.eduForm.degree = 2;
        this.eduFormList.push(
          this.eduForm
        );
      }else{
        this.$message({
          message: '请先填写高中教育信息',
          type: 'warning'
        });
      }
    },

    /**
     * 判断教育列表中是否有高中
     */
    isHasGaozhongFn(){
      let firstEdu = this.eduFormList[0];
      if(firstEdu){
        return (firstEdu.degree == 1) && firstEdu.id;
      }
    },
    //删除教育程度
    removeResumeEdu(eduId, index){
      if(eduId){
        this.$confirm('是否确定删除该条教育信息?', '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        }).then(() => {
          delEduObj(eduId).then(() => {
            var newList = this.eduFormList.filter( (currentValue,itemIndex,arr) => {
              return itemIndex != index;
            });
            this.eduFormList = newList;
            this.$notify({
              title: '成功',
              message: '删除成功',
              type: 'success',
              duration: 2000
            });
          });
        }).catch(() => {
              //点击取消         
        });
      }else{
        //前端移除
        var newList = this.eduFormList.filter( (currentValue,itemIndex,arr) => {
          return itemIndex != index;
        });
        this.eduFormList = newList;
      }

    },
    
    /**
     * 工作相关
     */
    //初始化工作-省份下拉列表
    getWorkProvinceOptions() {
      
      let pid = '';
      getAreaListObj(pid).then(res => {
        this.workProvinceOptions = res.data;
      });
    },
    workProvinceChange(work, data, index){
      work.provinceId = data.id;
      work.provinceName = data.name;
      work.cityId = '';
      work.cityName = '';
      getAreaListObj(data.id).then(res => {
        this.workCityOptions[index] = res.data;
        Vue.set(this.workCityOptions, index, res.data);
      });
    },
    workCityChange(work, data, index){
      work.cityId = data.id;
      work.cityName = data.name;
    },

    //添加工作信息
    addResumeWork(){
      this.workFormList.push(
        this.workForm
      );
    },
    //删除工作信息
    removeResumeWork(workId,index){
      //1.如果是新增的时候，点击删除，则直接前端删除, 否则调用后端删除
      if(workId){
        this.$confirm('是否确定删除该条工作信息?', '提示', {
            confirmButtonText: '确定',
            cancelButtonText: '取消',
            type: 'warning'
          }).then(() => {
            delWorkObj(workId).then(() => {
              var newList = this.workFormList.filter( (currentValue,itemIndex,arr) => {
                return itemIndex != index;
              });
              this.workFormList = newList;
              this.$notify({
                title: '成功',
                message: '删除成功',
                type: 'success',
                duration: 2000
              });
            });
          }).catch(() => {
              //点击取消         
          });
      }else{
        //前端移除
        var newList = this.workFormList.filter( (currentValue,itemIndex,arr) => {
          return itemIndex != index;
        });
        this.workFormList = newList;
      }
    },

    eduEndTimeFocus(index){
      //初始化教育信息的毕业时间-可选范围
      this.initEduPickerOptions(index);
    },

    /**
     * 设置不可选区间
     * time1: 结束时间
     */
    workSartTimeFocusFn(time1){
    //工作信息 结束日期禁用
    this.pickerOptions2 = {
        disabledDate(time) {
          if(time && time1){
            return time.getTime() > new Date(time1).getTime()
          }
          return false
        }
      }
    },

    /**
     * 设置不可选区间
     * time1: 开始时间
     */
    workEndTimeFocusFn(time1){
    //工作信息 结束日期禁用
    this.pickerOptions1 = {
        disabledDate(time) {
          if(time && time1){
            return time.getTime() < new Date(time1).getTime()
          }
          return false
        }
      }
    },

    /**
     * 教育信息的时间禁用
     * tip: 当前毕业时间的可选择范围 > 上一个教育信息的时间
     */
    initEduPickerOptions(index){
      let time1 = '', last = this.eduFormList[index-1];
      if(last){
         if(last.degree == 1){
            time1 = last.sessions
          }else if(last.endTime){
            time1 = last.endTime
          }
      }

      this.pickerOptions3 = {
        disabledDate(time) {
          if(time && time1){
            return time.getTime() < new Date(time1+'').getTime()
          }
          return false
        }
      }
    }

  }
}
</script>

<style rel="stylesheet/scss" lang="scss">
.box-card{
  margin: 10px 0;
}

</style>

